package com.raskasso.opengl;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.hardware.SensorManager;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;

import com.raskasso.opengl.listeners.AcelerometroListener;
import com.raskasso.opengl.renderer.PruebasRenderer;
import com.raskasso.opengl.surfaces.CameraPreview;

public class PruebasOpenGLActivity extends Activity {
	
	private AcelerometroListener acelerometroListener;
	
	private Camera mCamera;
    private CameraPreview mPreview;
    private GLSurfaceView mGLSurfaceView;
    private PruebasRenderer pruebasRenderer;
	
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	
    	super.onCreate(savedInstanceState);
     	
    	this.requestWindowFeature(Window.FEATURE_NO_TITLE); // (NEW)
    	this.setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 
    	getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
		 					WindowManager.LayoutParams.FLAG_FULLSCREEN); // (NEW)
        
    	pruebasRenderer=new PruebasRenderer();
    	
    	setGLSurfaceView(); 
		addCameraSurfaceView();  		
    }
    
    private void setGLSurfaceView() {
    	mGLSurfaceView = new GLSurfaceView(this);
    	mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); 
    	mGLSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT); 
    	mGLSurfaceView.setKeepScreenOn(true); 
    	
    	mGLSurfaceView.setRenderer(pruebasRenderer);
    	mGLSurfaceView.setZOrderOnTop(true);
		setContentView(mGLSurfaceView);
		
	}

	private void addCameraSurfaceView(){
    	 // Create an instance of Camera
        mCamera = Camera.open();

        // Create our Preview view and set it as the content of our activity.
        mPreview = new CameraPreview(this, mCamera);
        addContentView(mPreview,new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); 
    }
	
	 protected void onResume() {
         super.onResume();
         mGLSurfaceView.onResume();
     }

     protected void onPause() {
         super.onPause();
         mGLSurfaceView.onPause();
     }
}